// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias. 
//自动格式化的代码 按住Ctrl+K+F
import '@/assets/css/style.css'
import Vue from 'vue'
import App from './App'
import 'view-design/dist/styles/iview.css';
import 'element-ui/lib/theme-chalk/index.css';
import iView from 'view-design'; // 导入组件库
import Router from 'vue-router'
import router from './router'
import { Table, TableColumn,Loading,Tree} from 'element-ui';
import VueWechatTitle from 'vue-wechat-title'
import store from '@/store/index.js'; //公共状态管理

Vue.use(Table);
Vue.use(TableColumn);
Vue.use(Tree);
Vue.use(Loading.directive);

Vue.use(iView);
Vue.use(Router);
Vue.use(VueWechatTitle);
Vue.config.productionTip = false
var vueRouter = new Router({
  mode: 'history' //去掉#号的模式hash(#),history(无#)
  ,base:'/xgd-erp/'
})
//路由切换特效
vueRouter.beforeEach(function (to, from, next) {
  iView.LoadingBar.start();
  next();
});
vueRouter.afterEach(function (route) {
  iView.LoadingBar.finish();
});
window.gMain = {
  apiPath:'/'
  ,components:{
    iView:iView
  }
}; //全局变量

if(process.env.NODE_ENV == "development"){
  gMain.apiPath = '/api';
}else{
  gMain.apiPath = '/api';//'http://10.18.6.149:8080/api/'
}

/* eslint-disable no-new */
gMain.components.myApp = new Vue({
  el: '#bom_main_app',
  router:vueRouter,
  store,
  components: { App },
  template: '<App/>',
  mounted(){
    let t = this;
    let sUser = '';
    if (Object.keys(t.$route.query).length === 0){ //判断路由是否有?u=admin //管理员身份访问
      sUser = 'others';
    }else{
      sUser = t.$route.query.u||'others';
    }
    t.$store.commit('setSUser',sUser);
    vueRouter.addRoutes(router);
  }
})
